home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 19
/
CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso
/
CUCD
/
Readers
/
DoubleClick
/
Euclid.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-10-31
|
526b
|
39 lines
/* Euclid's Algorithm */
#include <stdio.h>
#include <exec/types.h>
/*
a,b are initial numbers
A[] is array to store numbers
n is counter
*/
ULONG a,b,A[200];
int n;
void main()
{
do
{
printf("Please Enter a Number...\n");
scanf("%d",&a);
if (a==0)
break;
printf("and Another Number...\n");
scanf("%d",&b);
A[0]=a;
A[1]=b;
n=0;
do
{
if (A[n] % A[n+1] == 0)
break;
A[n+2]=A[n] % A[n+1];
n++;
} while (1);
printf("\nThe hcf of %d and %d is %d\n\n",a,b,A[n+1]);
} while (1);
}